#include "factory_data.h"
#include "amLog.h"

typedef struct
{
	union
	{
		struct
		{
			uint8_t factoryTestState:1;
    		uint8_t boardCheckState:1;	
		}type;
		uint8_t value;
	}state;	
}FactoryData_st;

FactoryDataNessary_st g_factory_nessary;
BoardCheckData_st board_check_data;

static FactoryData_st factory_data;

uint8_t get_factory_status(uint8_t type)
{
	uint8_t ret = 0;

	switch(type)
	{
	case FACTORY_TYPE_BOARDCHECK:
		ret = factory_data.state.type.boardCheckState;
		break;
	case FACTORY_TYPE_FACCHECK:
		ret = factory_data.state.type.factoryTestState;
		break;
	default:
		ret = factory_data.state.value;
		break;
	}

	return ret;
}

void set_factory_status(uint8_t type, uint8_t value)
{
	switch(type)
	{
	case FACTORY_TYPE_BOARDCHECK:
		factory_data.state.type.boardCheckState = value;
		break;
	case FACTORY_TYPE_FACCHECK:
		factory_data.state.type.factoryTestState = value;
		break;
	default:
		factory_data.state.value = 0;
		break;
	}
}

static uint32_t *pu32BootVersion = (uint32_t*)(0x20000080);
uint32_t getbootloaderversion(void)
{
  return *pu32BootVersion;
}

static uint8_t g_board_id = 0;
void board_id_init(void)
{
    // g_board_id = BOARD_ID0_READ() | (BOARD_ID1_READ() << 1) | (BOARD_ID2_READ() << 2 | BOARD_ID3_READ() << 3);
}

uint8_t board_id_get(void)
{
    return g_board_id;
}

en_BoardNum board_num_get(void)
{
    /*  board id  Hardware consistent*/
    #define BOARD_ID_VA     0x00        //VA
    #define BOARD_ID_VB     0x01        //VB
    #define BOARD_ID_VC     0x02        //VC
    uint8_t id = board_id_get();
    switch(id)
    {
        case BOARD_ID_VA:
            return BOARD_NUM_VA;
        case BOARD_ID_VB:
            return BOARD_NUM_VB;
        case BOARD_ID_VC:
            return BOARD_NUM_VC;
        default:
            return BOARD_NUM_MAX;
    }
}
